<?

include_once '/var/www/html/new/d/module/api/ctrip/ctrip.class.php';
include('/var/www/html/new/d/module/api/function.class.php');

$ctrip = new Ctrip();
$PFT_infunction = new AllFunction();

if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

//{"VenueID":"","RoundID":"","AreaID":"","SeatID":"","Tnum":"1","Fid":"4274","PayStatus":"1","TicketID":"23385","TouristName":"\u6d4b\u8bd5pzp","TouristTel":"15959110796","PlayDate":"2015-08-26 00:00:00","IdCard":"0"}
	
$tid = 22229;
$selid = "select uuid,pid,tprice from uu_jq_ticket where id=".$tid." limit 1";
$GLOBALS['le']->query($selid);
if(!$GLOBALS['le']->fetch_assoc())	exit('101');		
$uuids = explode("_",$GLOBALS['le']->f('uuid'));  //查询票类id	
$ctrip_pid = $uuids[0]; //携程产品id
$ctrip_rid = $uuids[1]; //携程资源id
$pid = $GLOBALS['le']->f('pid');  //pid

$PlayDate = '2015-09-15';
$sellPrice_ldata = $PFT_infunction->Dynamic_Price_And_Storage('123697',$pid,$PlayDate,0,1,1,"27491");
if($sellPrice_ldata == 105 || $sellPrice_ldata == 1065) exit('1065|0|0|0|0');
$sellPrice_ldata_xml =simpleXML_load_string($sellPrice_ldata);
$sellPrice = (string)$sellPrice_ldata_xml->Rec->UUsprice;
$gprice = $sellPrice/100;

$ls_order = 'pft'.str_replace('.',mt_rand(1000,9999),microtime(true));
$request_array = array(
	'pftordername'	=> 'pzp',
	'UUordertel'	=> '15959110796',
	'IDcar'			=> '350321199108230123',
	'pftordernum'	=> $ls_order,
	'ProductID'		=> $ctrip_pid,
	'TicketID'		=> $ctrip_rid,
	'UUplaytime'	=> '2015-09-15',
	'UUtnum'		=> 1,
	'UUlprice'		=> $gprice,
);

$request = $ctrip->TicketOrderCreateForPrepay_V2($request_array);	
if($request['IsSucceed'] == 'true'){		
	logfile($ls_order.'|'.$request['IsSucceed'],'ctrip_submit_success'); //下单成功记录
	exit("200|0|0|0|0|".$ls_order);
}
else{
	logfile($ls_order.'|'.$request['ErrorMessage'],'ctrip_submit_fail'); //下单成功记录
	exit("101|0|0|0|0|0|");
}	
	 

function logfile($txt,$logname){
	$fp = fopen('/var/www/html/new/d/logs/api/ctrip/'.$logname.date('Y-m-d').'.txt',"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,date('Y-m-d H:i:s').'|'.$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp); 
}
?>